package com.example.springboottest.example.jaxws.hello.client;

import com.example.springboottest.example.jaxws.hello.HelloWorld;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

public class Client {
    private static final QName SERVICE_NAME = new QName("http://hello.jaxws.example.springboottest.example.com/", "HelloWorld");
    private static final QName PORT_NAME = new QName("http://hello.jaxws.example.springboottest.example.com/", "HelloWorldImplPort");

    public static void main(String[] args) throws MalformedURLException {
        System.out.println("Starting Client");

        // 定义Endpoint地址的内容
        String endpointAddress = "http://localhost:9000/HelloWorld";

        // 用服务名称创建一个服务
//		Service service = Service.create(SERVICE_NAME);
        Service service = Service.create(new URL(endpointAddress), SERVICE_NAME);

        // 从服务中增加端口
//		service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);

        service.getPorts().forEachRemaining(action -> {
            System.out.println(action.getLocalPart() + "\t" + action.getNamespaceURI());
        });
        // 获取服务类的对象并且处理
        HelloWorld helloWorld = service.getPort(PORT_NAME, HelloWorld.class);
        System.out.println(helloWorld.sayHello("方宁"));
        System.exit(0);
    }
}